package com.global.college.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.global.college.R;
import com.global.college.adapter.FreeCourseAdapter;
import com.global.college.api.ProgressSubscriber;
import com.global.college.api.RequestClient;
import com.global.college.base.BaseActivity;
import com.global.college.base.baselist.HnRecyclerGridDecoration;
import com.global.college.data.net.HomeGoodListBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 关于我们
 */
public class SearchActivity extends BaseActivity {

    @BindView(R.id.recycler_course)
    RecyclerView recyclerCourse;

    private FreeCourseAdapter freeCourseAdapter;

    @Override
    public int getContentViewId() {
        return R.layout.activity_search;
    }

    @Override
    public void onCreateNew(Bundle savedInstanceState) {
        setShowTitleBar(false);
    }

    @Override
    public void getInitData() {
        getSearchList();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
    }

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, SearchActivity.class);
        context.startActivity(intent);
    }

//    @OnClick({R.id.tv_show_net, R.id.ll_jump_to_net})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.tv_show_net:
//                break;
//            case R.id.ll_jump_to_net:
//                break;
//        }
//    }

    public void getSearchList(){
        RequestClient.getInstance().getGoodListBean(1).subscribe(new ProgressSubscriber<HomeGoodListBean>(this, false) {
            @Override
            public void onNext(HomeGoodListBean model) {
                if (freeCourseAdapter == null) {
                    freeCourseAdapter = new FreeCourseAdapter();
                    if (model.getGoodList().size() == 0) {
                        return;
                    }
//            StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(listSize, StaggeredGridLayoutManager.HORIZONTAL);
//            recyclerFree.setLayoutManager(layoutManager);
                    //设置为每行两列的列表
                    recyclerCourse.setLayoutManager(new GridLayoutManager(SearchActivity.this, 2));
                    recyclerCourse.addItemDecoration(new HnRecyclerGridDecoration(12));
                    freeCourseAdapter.bindToRecyclerView(recyclerCourse);
                }
                freeCourseAdapter.addData(model.getGoodList());
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        });
    }
}